package cn.tedu.charging.order.controller;

import cn.tedu.charging.order.pojo.param.OrderAddParam;
import cn.tedu.charging.order.pojo.vo.OrderDetailVO;
import cn.tedu.charging.order.service.OrderService;
import cn.tedu.charging.common.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags = "订单相关接口")
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @ApiOperation("创建订单")
    @PostMapping("create")
    public JsonResult creareOrder(@Validated @RequestBody OrderAddParam orderAddParam) {
        log.debug("创建订单的参数: orderAddParam : {} ", orderAddParam);
        // xxx 一些操作可能修改了入参
        log.debug("创建订餐参数service入参-{}",orderAddParam);
        String orderNo = orderService.createOrder(orderAddParam);
        log.debug("创建订餐参数service入参-{},出参-{}", orderAddParam, orderNo);
        JsonResult jsonResult = JsonResult.ok(orderNo,"订餐创建成功");
        log.debug("创建订单参数的入参-{},创建订单的出参--{}",orderAddParam,jsonResult);
        return jsonResult;
    }

    @ApiOperation("停止充电")
    @PostMapping("/normal/stop/{orderNo}")
    public JsonResult stop(@PathVariable("orderNo") String orderNo){
        log.debug("停止充电的入参-{}",orderNo);
        OrderDetailVO orderDetailVO = orderService.normalStop(orderNo);
        JsonResult result = JsonResult.ok(orderDetailVO, "停止成功,谢谢惠顾");;
        return result;
    }
}
